import Cookies from 'js-cookie'
import store from '@/store'
import fa from 'element-ui/src/locale/lang/fa'

const TokenKey = 'Admin-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function hasPerm(perm) {
  const permissions = store.getters && store.getters.permissions
  for (let i = 0; i < permissions.length; i++) {
    if (permissions[i] === '*:*:*') {
      return true;
    }
    if (permissions[i] === perm) {
      return true;
    }
  }
  return false
}
